{% extends "::base.html.twig" %}
{% block title %} Gerer les utilisateurs {% endblock %}
{% block other2 %}
	<div id="promo" class=".col-md-4">
		<h1 class="grey">Promotions</h1>
		{% set j=0 %}
		{% for i in users %}
			<div class="promo {% if promo is defined %}{% if i.promoid==promo %}first{% endif %}{% else %}{% if j==0 %}first{% set j=1 %}{% endif %}{% endif %}" data-id="tab{{i.promoid}}" data-pid="{{i.promoid}}">{{i.promo}} <i class="icon-uniE646"></i></div>
		{% endfor %}
	</div>
{% endblock %}
{% block other %}
	<h1><i id="openMenu" class="icon-list tooltips" title="Ouvrir le Menu"></i>Gérer les Utilisateurs</h1>
{% endblock %}
{% block body %}
    <a href="{{path('fos_user_registration_register')}}"><i class="icon-plus blue"></i>Enregister un utilisateur</a>
	<div>
		<div id="users" class=".col-md-8">
		{% for i in users %}
			<table id="tab{{i.promoid}}">
			<thead>
				<tr style="padding: 0;">
					<td colspan="4" style="padding:0 !important; margin:0 !important;">
						<h1 style="margin: 0 !important; width: 100%;"> {{i.promo}}</h1>
					</td>
				</tr>
				<tr>
					<td>Nom d'utilisateur</td>
					<td>Email</td>
					<td>Dernière Connexion</td>
					<td>Actions</td>
				</tr>
			</thead>
			<tbody>
				{% for u in i.users %}
					{% if not u.isSuperAdmin() %}	
							<tr>
								<td>{{u.username}}</td>
								<td>{{u.email}}</td>
								<td>{{ u.lastLogin | date("d/m/y") }}</td>
								<td>
									<a class="open" href="{{ path("readAllEleveQuizz",{idUser:u.id}) }}"><i class="icon-enter tooltips" title="Voir les notes"></i></a>
		    						<a class="pass" href="{{path('changePassword',{id:u.id}) }}"><i class="icon-lock tooltips"  title="Changer mot de passe"></i></a>
		    						<a class="update" href="{{path('updateUser',{id:u.id}) }}"><i class="icon-pencil round tooltips"  title="Editer"></i></a>
									<a class="delete" href="{{ path("deleteUser",{id:u.id}) }}"><i class="icon-remove red round tooltips" title="Supprimer"></i></a>
								</td>
							</tr>
					{% endif %}
				{% endfor %}
			</tbody>
			</table>
		{% endfor %}
		</div>
	</div>

	<div id="info">
		<i class="icon-info2 tooltips round black"  title="Pour changer de promotion, cliquez sur le bouton <b class='icon-list'></b><br/> La promotion séléctionnée est enregistrée pour le prochain chargement.">
		</i>
	</div>
	<script>
		$(document).ready(function(){
			$("#users").on('click',' a.delete',function(e){
				e.preventDefault();
				if (confirm('La suppression d\'utilisateur est irreversible, tous les quizz qu\'il aura fait le seront eux aussi. \nVoulez vous continuer ?')) {
				    document.location.href=$(this).attr("href");
				} 
				return false;
			});
			$('#openMenu').on('click',function(){
				$("#promo").animate({left:0},750);
			});
			$("#promo").on('click',' .promo',function(){
					elem=$(this).parent();
					if(window.screen.width>550){
						elem.animate({left:-400},750);
					}else{
						$("html,body").animate({scrollTop:$("#users").offset().top});
					}
					if(!$(this).attr("class").match("active")){
						if(typeof($("#promo .active").attr("class"))!="undefined"){
							$("#"+$("#promo .active").attr("data-id")).hide();
							$("#promo .active").removeClass('active');
						}
						$(this).addClass('active');
						$("#"+$(this).attr("data-id")).fadeIn(750);
						$.ajax({
							url: '{{ path("setSession") }}',
							type: 'POST',
							data: {id: $(this).attr("data-pid") }
						});
						
					}
			});
			$("#promo .first").addClass('active');
			$("#"+$("#promo .first").attr("data-id")).show();
		});
	</script>
{% endblock %}